package com.bawei.lib_common.manager

import androidx.lifecycle.MutableLiveData
import com.bawei.lib_net.msgbus.LiveDataBus

/**
 * 全局数据管理器
 * 用于管理跨模块的实时数据
 */
object GlobalDataManager {
    
    // 购物车数量
    private val _cartCount = MutableLiveData<Int>(0)
    val cartCount: MutableLiveData<Int> = _cartCount
    
    // 收藏数量
    private val _collectCount = MutableLiveData<Int>(0)
    val collectCount: MutableLiveData<Int> = _collectCount
    
    // LiveDataBus的key
    const val CART_COUNT_KEY = "cart_count"
    const val COLLECT_COUNT_KEY = "collect_count"
    
    /**
     * 更新购物车数量
     */
    fun updateCartCount(count: Int) {
        _cartCount.postValue(count)
        // 同时通过LiveDataBus发送，确保跨模块同步
        LiveDataBus.with<Int>(CART_COUNT_KEY).postValue(count)
    }
    
    /**
     * 更新收藏数量
     */
    fun updateCollectCount(count: Int) {
        _collectCount.postValue(count)
        // 同时通过LiveDataBus发送，确保跨模块同步
        LiveDataBus.with<Int>(COLLECT_COUNT_KEY).postValue(count)
    }
    
    /**
     * 获取当前购物车数量
     */
    fun getCurrentCartCount(): Int = _cartCount.value ?: 0
    
    /**
     * 获取当前收藏数量
     */
    fun getCurrentCollectCount(): Int = _collectCount.value ?: 0
} 